package com.capgemini.teamtwo.controller;

import com.capgemini.teamtwo.common.ResponseBean;
import com.capgemini.teamtwo.entity.ProjectSchedule;
import com.capgemini.teamtwo.entity.vo.ProjectScheduleVO;
import com.capgemini.teamtwo.service.ProjectScheduleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@Api("进度配置管理")
@RestController
@RequestMapping("/project")
public class ProjectScheduleController {

    @Autowired
    private ProjectScheduleService projectScheduleService;


    /**
     * 查询进度配置计划
     * @param projectId 项目id
     * @return 项目计划的信息
     */
    @ApiOperation("查询进度配置计划")
    @GetMapping("/select_schedule")
    public ResponseBean<ProjectSchedule> list(@RequestParam Integer projectId){
        List<ProjectSchedule> projectSchedule = projectScheduleService.findScheduleById(projectId);
        return ResponseBean.success(projectSchedule);
    }

    /**
     * 新增进度配置计划
     * @param projectScheduleVO 前端表单数据
     * @return 新增计划详细信息
     */
    @ApiOperation("新增进度配置计划")
    @PostMapping("/add_schedule")
    public ResponseBean<ProjectSchedule> addSchedule(@RequestBody ProjectScheduleVO projectScheduleVO){
        ProjectSchedule projectSchedule = projectScheduleService.insertProjectSchedule(projectScheduleVO);
        return ResponseBean.success(projectSchedule);

    }

    /**
     * 编辑进度配置计划
     * @param projectScheduleVO 前端表单数据
     * @return 编辑计划详细信息
     */
    @ApiOperation("编辑进度配置计划")
    @PostMapping("/edit_schedule")
    public ResponseBean editSchedule(@RequestBody ProjectScheduleVO projectScheduleVO){
        projectScheduleService.updateProjectSchedule(projectScheduleVO);
        return ResponseBean.success("编辑成功");
    }

}
